# -*- mode: Python; coding: utf-8 -*-
#
# Fabric deployment script for Streamux.

# ae-streaming is not directly accessible by ssh, so you'll need a
# tunnel from localhost to deploy. If you don't know how to do that
# and the AE-info team won't tell you, you're probably not authorized
# to deploy anyway.
set(fab_hosts = ['localhost'],
    fab_port = 2345,
    fab_user = 'radio')

def dcommit():
    local('git svn dcommit')

def reload():
    "Reload the Streamux webapp"
    run('touch streamux/streamux.fcgi')

def syncdb():
    "Run manage.py syncdb"
    run('cd streamux && ./manage.py syncdb')

def update():
    "Run svn update"
    run('svn update')

def restartdaemon():
    "Restart the music processing daemon"
    run('cd streamux && ./manage.py restartdaemon')

def genliqconfig():
    "Regenerate the liquidsoap configuration"
    run('cd streamux && ./manage.py genliqconfig')

def push():
    "Push new files to the site, nothing else"
    dcommit()
    update()
    genliqconfig()

def deploy():
    "Deploy an updated website only"
    push()
    syncdb()
    reload()

def deploy_daemon():
    "Depoy an updated daemon only"
    push()
    syncdb()
    restartdaemon()

def deploy_all():
    "Deploy the latest version from Subversion"
    push()
    syncdb()
    reload()
    restartdaemon()

def reset_db():
    "DESTROY ALL DATA and reset the SQL schema for streamux."
    run('cd streamux && ./manage.py reset radio --noinput')
    run('cd streamux && ./manage.py reset auth --noinput')
